#include "tlabel.h"

#include <QPaintEvent>
#include <QPainter>

TLabel::TLabel(QWidget *parent)
    : QWidget(parent)
{
}

TLabel::~TLabel()
{
}

void TLabel::setText(const QString &text)
{
    m_text = text;
    QFontMetrics fm = fontMetrics();
    QSize size = fm.size(Qt::TextSingleLine, text);
    setMinimumSize(size);

    update();
}

void TLabel::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);
    painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing); //设置渲染特性：反锯齿

    painter.drawText(event->rect(), m_text);
    painter.end();
}
